<template>
	<view class="mypage">
		
		<view class="list" v-for="(item,index) in subcontractlist" :key="index">
			<view class="left">
				<view class="img-box" style="padding-right: 30rpx;">
          <image style="padding-right: 20rpx;" src="../../../static/images/bigmaster.png"></image>
         </view>
				<view class="info-person" @click="todetail(item.id)">
					<view class="">{{item.unitName}}</view>
					<view class="zi"><text>{{item.unitOwnName}}</text>&nbsp;&nbsp;<text  style="margin-left: 15rpx;">{{item.unitOwnPhone}}</text></view>
				</view>
			</view>
			<view class="right">
				<view class="" @click="mySelect(item.id)">详情&nbsp;</view>
				<view class="" v-if="false" @click="myDelete(item.id)" style="margin-left: 15rpx;">删除</view>
			</view>
		</view>
		
		<view class="enter-btn">
			<button @click="toaddsubcontracting">添加分包单位</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				  id: 1,
				  orderBy: "",
				  pageNo: 1,
				  pageSize: 10,
				  returnFields: "",
				  unitName: "",
				  unitType: 0,
				  subcontractlist:[]
			}
		},
		onLoad() {
			// this.getsubcontract()
		},
		onShow() {
			this.getsubcontract()
			console.log(1111);		
		},
		methods: {
      myDelete(id){
		  let that=this
        uni.showModal({
          title: '提示',
          content: '确定要删除分包单位',
          success(res) {
            console.log('res',res);
            if(res.confirm){
              // 发送删除请求
			  console.log(that.path);
			  uni.$delete(that.path+'/unit/delete',[
				  parseInt(id)
			  ]).then(res=>{
				  if(res.code==200){
					 uni.showToast({
					   title: '删除成功',
					   icon: 'none',
					   duration:1500
					 }) 
					 that.getsubcontract()
				  }else{
					  uni.showToast({
					    title: '无法删除',
					    icon: 'error',
						duration:1500
					  })
				  }
			  })
             
            }
            if(res.cancel){
              // 用户点击取消
            }
          }
        })
      },
      mySelect(id){
        console.log(id);
        uni.navigateTo({
          url: './addsubcontracting?selectId=' + id
        })
      },
			toaddsubcontracting(){
				uni.navigateTo({
					url:'./addsubcontracting'
				})
			},
			getsubcontract(){
				uni.$post(this.path+'/unit/query',{
          id: '',
					orderBy: "",
					pageNo: 1,
					pageSize: 1000,
					returnFields: "",
					unitName: "",
					unitType: 4,
          unitFlag: 1
				}).then(res=>{
					if(res.code==200){
						this.subcontractlist=res.data.records
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .mypage{
    padding-bottom: 100rpx;
  }
.list{
		display: flex;
		width: 95%;
		margin: 0 auto;
		margin-top: 10px;
		justify-content: space-between;
		align-items: center;
		height: 140rpx;
		border-radius: 5px;
		background-color: white;
		.left{
			width: fit-content;
			height: 80rpx;
			display: flex;
			justify-content: space-around;
			.img-box{
				width: 60rpx;
				height: 60rpx;
				margin-left: 10rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.info-person{
				width: fit-content;
				min-width: 200rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				height: 90rpx;
				font-size: 13px;
				
				.zi{
					font-size: 12px;
					color: #c1c1c1;
				}
				
			}
			
		}
		.right{
			margin-right: 10rpx;
			width: fit-content;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 100rpx;
			font-size: 12px;
			color: #c1c1c1;
		}
	}
	.enter-btn{
		position: fixed;
		bottom: 20rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		button{
			width: 80%;
			background-color: #2f67ff;
			height: 35px;
			line-height: 35px;
			color: white;
			font-size: 14px;
		}
	}
</style>
